﻿namespace PrismEx.Fixtures.Events
{
    using NUnit.Framework;

    using PrismEx.Events;

    using Stump;

    [TestFixture]
    public class ReactiveEventFixture : TestFixtureBase<ReactiveEvent<string>>
    {
        private int eventHandledCount = 0;

        public override void Given()
        {
            this.TestDomain = new TestDomain<ReactiveEvent<string>>(new ReactiveEvent<string>());
        }

        public override void When()
        {
            var token = TestDomain.Subject.Subscribe(o => eventHandledCount++);
            TestDomain.Subject.Publish("SomeValue");
            TestDomain.Subject.Unsubscribe(token);
            TestDomain.Subject.Publish("SomeValue");
        }

        [Then(Description = "Callback should be called only before the unsubscription")]
        public void ShouldUnsubscribeWhenTokenIsDisposed()
        {
            Assert.That(eventHandledCount, Is.EqualTo(1));
        }
    }
}